import { useState } from "react"
import { Button, Modal } from 'antd';
import { Form, Input } from 'antd';
//分享按钮组件
const LoginButton = (flag) => {
    const [isModalVisible, setIsModalVisible] = useState(flag);
    //确认
    const handleOk = () => {
        setIsModalVisible(false);
    };
    //取消
    const handleCancel = () => {
        setIsModalVisible(false);
    };
    const onFinish = (values) => {
        localStorage.setItem("user", JSON.stringify(values))
        setIsModalVisible(false);
    };
    return ( //搜索按钮
        <div>
            <Modal title="搜索"
                visible={isModalVisible}
                onOk={handleOk}
                onCancel={handleCancel}
                okText="确认"
                cancelText="取消"
                width={600}>
                <Form
                    name="basic"
                    labelCol={{ span: 8 }}
                    wrapperCol={{ span: 16 }}
                    initialValues={{ remember: true }}
                    onFinish={onFinish}
                    autoComplete="off"
                >
                    <Form.Item
                        label="用户名"
                        name="username"
                        rules={[{ required: true, message: '请输入用户名' }]}
                    >
                        <Input />
                    </Form.Item>

                    <Form.Item
                        label="邮箱"
                        name="email"
                        rules={[{ required: true, message: '请输入邮箱' }]}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                        <Button type="primary" htmlType="submit">
                            登录
                        </Button>
                    </Form.Item>
                </Form>
            </Modal>
        </div>
    )
}

export default LoginButton;